package picasa;

import java.awt.Color;
import java.awt.image.RGBImageFilter;

class SepiaFilter extends RGBImageFilter {
	int depth;
	
	public SepiaFilter(int d){
		if (d < 0){
			d = 0;
		}
		depth = d;
		canFilterIndexColorModel = true;
	}
	
	public SepiaFilter(){
		this(25);
	}
	
	public int filterRGB(int x, int y, int rgb){
		int r, g, b, gry;
		
		Color c = new Color(rgb);
		r = c.getRed();
		g = c.getGreen();
		b = c.getBlue();
		
		gry = (r + g + b) / 3;
		r = g = b = gry;
		
		r = r + (depth * 2);
		g = g + depth;
		if (r > 255){
			r = 255;
		}
		if (g > 255){
			g = 255;
		}
		c = new Color(r, g, b);
		return c.getRGB();
	}
}